from socket import socket, AF_INET, SOCK_STREAM
import select,sys
tcp_client = socket(AF_INET, SOCK_STREAM)
server_addr = ('192.168.76.128', 2000)
tcp_client.connect(server_addr)
epoll = select.epoll()
epoll.register(sys.stdin.fileno(),select.EPOLLIN)
epoll.register(tcp_client.fileno(),select.EPOLLIN)
while True:
    event_list=epoll.poll(-1)
    for fd,event in event_list:
        if fd==tcp_client.fileno():
            recv_data = tcp_client.recv(1000)
            if recv_data:
                print(recv_data.decode('utf8'))
            else:
                print('对方断开')
                break
        elif fd==sys.stdin.fileno():
            data = input()
            tcp_client.send(data.encode('utf8'))
